package org.idea.qiyu.framework.jmh.demo;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.TimeUnit;

import static org.openjdk.jmh.annotations.Mode.AverageTime;
import static org.openjdk.jmh.annotations.Mode.Throughput;

/**
 * JMH基准测试
 */
@BenchmarkMode(Throughput)
@Fork(2)
@Warmup(iterations = 4)
@Threads(4)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class JMHHelloWord {

    @Benchmark
    public void baseMethod() {
    }

    @Benchmark
    public void measureWrong() {
        String item = "";
        item = item + "s";
    }

    @Benchmark
    public String measureRight() {
        String item = "";
        item = item + "s";
        return item;
    }


//    public static void main(String[] args) throws RunnerException {
//        Options options = new OptionsBuilder().
//                include(JMHHelloWord.class.getName()).
//                build();
//        new Runner(options).run();
//    }

}
